﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SuperStarProject.DAO;
using SuperStarProject.Models;

namespace SuperStarProject.Controllers
{
    public class QuaTangController : Controller
    {
        //
        // GET: /QuaTang/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ShowAll(string maSP)
        {
            var lstQuaTang = QuaTangDAO.ShowAll(maSP);
            return View(lstQuaTang);
        }
        public ActionResult ShowAllWithComboBox(string maSP)
        {
            var lstQuaTang = QuaTangDAO.ShowAll(maSP);
            // Xu ly so toi da.
            return View(lstQuaTang);
        }
        public ActionResult ShowAllImage(string maSP)
        {
            var lstQuaTang = QuaTangDAO.ShowAll(maSP);
            return View(lstQuaTang);
        }
        public ActionResult ViewDetails(string ma)
        {
            var product = QuaTangDAO.ViewDetails(ma);
            return View(product);
        }
        [HttpGet]
        public ActionResult CreateQuaTangNhanVien(string masanpham)
        {
            QuaTangModel item = new QuaTangModel();
            item.MaSanPham = masanpham;
            return View(item);
        }
        [HttpPost]
        public ActionResult CreateQuaTangNhanVien(QuaTangModel model)
        {
            //KT
            //Luu xuong CSDl
            if (QuaTangDAO.CreateQuaTang(model,User.Identity.Name))
                return RedirectToAction("ViewDetails", "QuaTang", new { ma = model.MaQua });
            else
                return RedirectToAction("ShowAllSPNhanVien", "Product");
        }
    }
}
